package com.intech.android.demo.dao.impl;

import com.intech.android.demo.bo.Person;
import com.intech.android.demo.dao.interfaces.PersonDAO;
import org.apache.log4j.Logger;
import org.hibernate.Query;

public class PersonHibernateDAO extends CommonDAO implements PersonDAO
{
    private static final Logger log = Logger.getLogger(PersonHibernateDAO.class);

    public void save(Person person)
    {
        System.out.println("!!!!!!!!!!!!!!!!!!!!! saved");
        session.saveOrUpdate(person);
    }


    public void delete(int id)
    {
        Person person = getById(id);

        session.delete(person);
    }

    public Person getById(int id)
    {
        return (Person) session.get(Person.class, id);
    }

    public Person getByLogin(String login)
    {
        Query query = session.createQuery
                ("select p  from com.intech.android.demo.bo.Person  as p where p.username = :Name");
        query.setParameter("Name", login);
        Person person = (Person) query.uniqueResult();
        return person;
    }


}
